require('../../assets/css/index.less');
require('./introduce.less');
require('./iconfont/iconfont.css')
// 获取ajax工具
let request= require('../../xios/axios')
window.onload = () => {
    console.log(location);
    // console.log(location.search);
  let loc=  location.search.split('=')[1]
    console.log(location.search.split('=')[1]);
    // 获取数据
    function getData2(){
          request.get('/api/train/courseDetail',{
             params:{
              id:loc,
             }
          }).then(res=>{
              let{errno,data}=res.data
              console.log(res);
              if(errno===0){
                // console.log(data.fragments);
                localStorage.setItem('fragments',JSON.stringify(data.fragments))
                fa(data)
              }
          })
    }
    getData2()  
  const API='http://fitness.h5.itsource.cn:3701'
//获取dom
let vid=document.querySelector('.vid')
console.log(vid);
// 获取本地数据
let fragments= JSON.parse(localStorage.getItem('fragments'))
console.log(fragments);
 // 设置变量
 vid.src = API + fragments[0].videoUrl
  // 设置变量
  let index = 0 //初始化变量索引
  let length = fragments.length  //获取视屏总个数
  
  
  let btom_hn= document.querySelector('.btom_hn')
  let sp2= document.querySelector('.sp2')
  let sp3= document.querySelector('.sp3')
  let sp4= document.querySelector('.sp4')
  let con = document.querySelector('#con')
  let top_p = document.querySelector('#top_p')
  let con_p3 = document.querySelector('#con_p3')
  let ghz_sp3 = document.querySelector('.ghz_sp3')
  let spp = document.querySelector('#spp')
  function fa(data){
    btom_hn.innerHTML=data.name
    sp2.innerHTML=data.calorie  
   sp3.innerHTML=data.time   
   sp4.innerHTML=data.peoplenum
   con_p3.innerHTML=data.desc
   spp.textContent = index + 1
    // 给视频src赋值
    vid.src = API + fragments[index].videoUrl
  //  frequency
  ghz_sp3.innerHTML=data.frequency
  }
  
// 获取个人资料
  request.get('/api/user/info').then(res=>{
     let {errno,data}=res.data
     console.log(data.imgUrl);
     console.log(res);
     if(errno===0){
        con.src=API+data.imgUrl
        top_p.innerHTML=data.nickName
     }
  })
  // 自动切换下一个视频
  vid.addEventListener('ended',()=>{
     // 给视频src赋值
     index++
    if(index<4){
      vid.src = API + fragments[index].videoUrl
      vid.play()
    }else{
      index=0
      vid.src = API + fragments[index].videoUrl
      vid.play()
    }
  })
let but=  document.querySelector('.but')
but.addEventListener('click',function(){
  location.href='./play.html'
})
} 